/*
 * A queue holding all tasks to be executed - in our case these are lines
 * to be written to the file.
 */
#ifndef SYNCEDTASKSQUEUE_H_
#define SYNCEDTASKSQUEUE_H_

#include <queue>
#include <set>
#include <pthread.h>
#include <string>
#include "Task.h"
using namespace std;


class SyncedTasksQueue {
private:
	//a queue of tasks:
	queue<Task*> _tasks;

	//The lock needed for accessing the queue:
	pthread_mutex_t _queueMutex;


public:
	//constructor:
	SyncedTasksQueue() : _tasks(){//, _tasksId(){
		pthread_mutex_init(&_queueMutex, NULL);
		_tasks = queue<Task*>();
	};

	//destructor:
	~SyncedTasksQueue(){
		pthread_mutex_destroy(&_queueMutex);
	}

	//Adds a new task to the end of the queue:
	void pushTask(Task* task);

	//Return the task at the top of the queue or null if the queue is empty.
	Task* popTask();

	//Returns true if the queue is empty, false otherwise.
	bool empty();
};

#endif /* SYNCEDTASKSQUEUE_H_ */
